package com.personal.gateway.flinkAllCommand;

import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOption;
import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOptionBuilder;
import com.personal.gateway.flinkAllCommand.configurationOption.KeyIndexInfomationDao;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationGenerator.ConfigurationGeneratorInteger;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationType.AbstractConfigurationTypeClass;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationType.ConfigurationTypeInteger;
import com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck.ParameterCheckInteger;
import com.personal.gateway.flinkAllCommand.configurationOption.webObjectGenerator.WebObjectGeneratorInteger;

import static com.personal.gateway.flinkAllCommand.FlinkExecuteCommand.MEMORY_CONFIG;

/**
 * @author BigHead
 * @date 2022/1/20 15:42
 * @description FlinkMemory
 */
public class FlinkMemory extends AbstractConfigurationTypeClass {

    public static final Class<AbstractConfigurationTypeClass> FLINK_MEMORY_TYPE_CLASS = (Class<AbstractConfigurationTypeClass>) (Class<?>) FlinkMemory.class;


    private final ConfigurationOption<Integer, ConfigurationTypeInteger> JM_MEMORY_PROCESS_SIZE = ConfigurationOptionBuilder
            .startBuilder(MEMORY_CONFIG, new KeyIndexInfomationDao("JM_MEMORY_PROCESS_SIZE", 1))
            .webShowName("JM内存")
            .describe("JobManager的总进程内存大小。这包括JobManager JVM进程消耗的所有内存，包括总Flink内存、JVM元空间和JVM开销。在容器化设置中，这应该设置为容器内存")
            .typeInteger()
            .setExampleValue(1024)
            .setMinMaxValue(1024, 100000)
            .webObjectGenerator(WebObjectGeneratorInteger.class)
            .parameterCheck(ParameterCheckInteger.class)
            .configurationGenerator(ConfigurationGeneratorInteger.class)
            .build();

    private final ConfigurationOption<Integer, ConfigurationTypeInteger> TM_MEMORY_FLINK_SIZE = ConfigurationOptionBuilder
            .startBuilder(MEMORY_CONFIG, new KeyIndexInfomationDao("TM_MEMORY_FLINK_SIZE", 2))
            .webShowName("TM内存")
            .describe("taskexecutor的Flink总内存大小。这包括TaskExecutor消耗的所有内存，除了JVM metspace和JVM开销。它由框架堆内存、任务堆内存、任务堆外内存、托管内存和网络内存组成。")
            .typeInteger()
            .setExampleValue(1024)
            .setMinMaxValue(1024, 100000)
            .webObjectGenerator(WebObjectGeneratorInteger.class)
            .parameterCheck(ParameterCheckInteger.class)
            .configurationGenerator(ConfigurationGeneratorInteger.class)
            .build();

    private final ConfigurationOption<Integer, ConfigurationTypeInteger> TM_SLOT_NUM = ConfigurationOptionBuilder
            .startBuilder(MEMORY_CONFIG, new KeyIndexInfomationDao("TM_SLOT_NUM", 3))
            .webShowName("Slot个数")
            .necessary(false)
            .describe("单个TaskManager可以运行的并行操作符或用户函数实例的数量。如果该值大于1，则单个TaskManager接受一个函数或操作符的多个实例。通过这种方式，TaskManager可以使用多个CPU核，但同时，可用的内存被分配给不同的操作符或函数实例。这个值通常与TaskManager机器的物理CPU核数成比例(例如，等于核数，或核数的一半)。")
            .typeInteger()
            .setExampleValue(1, 2, 3)
            .setMinMaxValue(1, 100000000)
            .webObjectGenerator(WebObjectGeneratorInteger.class)
            .parameterCheck(ParameterCheckInteger.class)
            .configurationGenerator(ConfigurationGeneratorInteger.class)
            .build();

}
